package com.oocl.client;

import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.global.GlobalVar;
import com.oocl.server.po.ClientInfo;

public class ClientInfoList {
	private static Socket socket;
	
	public ClientInfoList(Socket socket) {
		super();
		ClientInfoList.socket = socket;
	}
	
	public void deleteClientInfo() {
		if (GlobalVar.infoList.size() == 1) {
			GlobalVar.infoList.clear();

		} else {
			for (ClientInfo clientInfo : GlobalVar.infoList) {
				if (clientInfo.getClientIP() == socket.getInetAddress()) {
					GlobalVar.infoList.remove(clientInfo);
				}
			}
		}
	}
	
	public void addClientInfo() {
		InetAddress ip = socket.getInetAddress();
		ClientInfo info = new ClientInfo(ip, new java.util.Date());
		GlobalVar.infoList.add(info);
	}
	
	public List<ClientInfo> getClinetsInfo() throws UnknownHostException {
		List<ClientInfo> clientInfos = new ArrayList<ClientInfo>();
		if (!GlobalVar.infoList.isEmpty()) {
			clientInfos = GlobalVar.infoList;
		}
		
		return clientInfos;

	}
}
